import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { User } from '../../../users/entities/user.entity';
import { MembershipPackage } from '../../membership/entities/membership-package.entity';

/**
 * 用户会员状态实体
 */
@Entity({ name: 'user_memberships', comment: '用户会员状态表' })
export class UserMembership {
  @ApiProperty({ description: '会员记录ID' })
  @PrimaryGeneratedColumn({ comment: '会员记录ID' })
  id: number;

  @ApiProperty({ description: '用户ID' })
  @Column({ comment: '用户ID' })
  userId: number;

  @ApiProperty({ description: '套餐ID' })
  @Column({ comment: '套餐ID' })
  packageId: number;

  @ApiProperty({ description: '会员开始时间' })
  @Column({ 
    type: 'datetime',
    comment: '会员开始时间' 
  })
  startTime: Date;

  @ApiProperty({ description: '会员结束时间' })
  @Column({ 
    type: 'datetime',
    comment: '会员结束时间' 
  })
  endTime: Date;

  @ApiProperty({ description: '是否生效中' })
  @Column({ 
    default: true,
    comment: '会员是否生效中' 
  })
  isActive: boolean;

  @ApiProperty({ description: '支付金额（单位：分）' })
  @Column({ 
    type: 'int',
    comment: '实际支付金额，单位分' 
  })
  paidAmount: number;

  @ApiProperty({ description: '创建时间' })
  @CreateDateColumn({ comment: '记录创建时间' })
  createdAt: Date;

  @ApiProperty({ description: '更新时间' })
  @UpdateDateColumn({ comment: '记录更新时间' })
  updatedAt: Date;

  // 关联用户
  @ManyToOne(() => User)
  @JoinColumn({ name: 'userId' })
  user: User;

  // 关联套餐
  @ManyToOne(() => MembershipPackage)
  @JoinColumn({ name: 'packageId' })
  package: MembershipPackage;
}